#ifndef AUDIOOUTPUT_H
#define AUDIOOUTPUT_H

#include <QDebug>

extern "C" {
#include "SDL.h"
#include "libswresample/swresample.h"
}

#include "avframequeue.h"
#include "avsync.h"

typedef struct  AudioParams
{
    int freq; //采样率
    int channeles;
    int64_t channel_layout;
    enum AVSampleFormat fmt;
    int frame_size;
}AudioParams;

class AudioOutput
{
public:
    AudioOutput(AVSync *avsync, AVRational time_base, const AudioParams &audio_params, AVFrameQueue *frame_queue);
    ~AudioOutput();

    int Init();
    int DeInit();

public:
    AudioParams src_tgt_; //解码后的参数
    AudioParams dst_tgt_l; //SDL实际输出格式
    AVFrameQueue *frame_queue_ = nullptr;

    struct SwrContext *swr_ctx_ = nullptr;

    uint8_t *audio_buf_ = nullptr;
    uint8_t *audio_buf1_ = nullptr;
    uint32_t audio_buf_size = 0;
    uint32_t audio_buf1_size = 0;
    uint32_t audio_buf_index = 0;

    AVSync *avsync_ = nullptr;
    AVRational time_base_;
    int64_t pts_ = AV_NOPTS_VALUE;


};

#endif // AUDIOOUTPUT_H
